from pymysql import Connection

try:
    conn = Connection(     # 连接数据库
        host='10.13.10.53',
        port=3306,
        user='tester',
        password='AY^1F6pZlkVx9jqd',
        autocommit=False
    )
    conn.select_db('open_employ')    # 要操作的库名
    cursor = conn.cursor()      # 获取数据库游标对象

    sql = "update open_employ.attend_machine_record set name = '摩卡猫猫' " \
          "where worker_no = 80001799 and clock_time = '2025-03-25 23:00:18'"
    rows = cursor.execute(sql)

    # 因连接数据库时，autocommit=False，没有自动提交事务，此时需要手动提交事务
    conn.commit()     # 数据库提交事务

    print(f'更新{rows}条数据成功')

except Exception as e:
    print(f'发生错误,{e}')
finally:
    if 'cursor' in locals() and cursor:
        cursor.close()
    if 'conn' in locals() and conn:
        conn.close()
    print(f"sql执行完成，关闭数据库连接")
